<template>
  <div class="login">
    <!-- 1.绘制静态页面 -->

    <div class="con">
      <!-- 2.绑定数据 -->
      <h3 class="text-center">登录</h3>
      <el-input placeholder="请输入账号" clearable v-model="form.username"></el-input>
      <el-input placeholder="请输入密码" clearable show-password v-model="form.password"></el-input>
      <div class="text-center">
        <el-button type="primary" @click="login">登录</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { requserlogin } from "../../http/api";
import { mapActions } from "vuex";
export default {
  data() {
    return {
      //1.初始化数据
      form: {
        username: "",
        password: ""
      }
    };
  },
  mounten() {},
  // 4 引入
  methods: {
    ...mapActions({
      changeInfo:'changeInfo'
    }),
    // 3.点击登录--发请求
    login() {
      requserlogin(this.form).then(res => {
        if (res.data.code == 200) {
          //3.1 存用户信息--->vuex根级别--res.data.list里面是用户信息
          this.changeInfo(res.data.list)
        
          // 3.2 调转页面
          this.$router.push('/index/home')
        }
      });
    }
  }
};
</script>

<style scoped lang="less" scoped>
@import "../../less/index.less";
.login {
  width: 100vw;
  height: 100vh;
  background: linear-gradient(to right, @primary, @middle, @deep);
  position: relative;
}
.con {
  width: 350px;
  padding: @padding;
  background: #fff;
  border-radius: @radius;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
h3 {
  margin-bottom: @padding;
}
.el-input {
  margin-bottom: @margin;
}
.text-center {
  text-align: center;
}
</style>